package love.yuanmengrobot.wuziqi.UIyqh;

import love.yuanmengrobot.wuziqi.UI.StrtForm;
import love.yuanmengrobot.wuziqi.Util.Main;
import love.yuanmengrobot.wuziqi.Util.Trade;

import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.*;

import static java.lang.Thread.sleep;

/*
 *   @Studio:CHJY · 源梦科技
 *   @Author:COOLIGHT
 *   @Ide:多人五子棋
 *   @Creation time:2021/5/8
 */

public class MallForm extends JFrame {
    String relativePath = "src/love/yuanmengrobot/wuziqi/images/";//图片相对路径
    String userId;//用户id
    Thread thread;//监控支付的线程
    private StrtForm strtForm;

    public StrtForm getStrtForm() {
        return strtForm;
    }

    public void setStrtForm(StrtForm strtForm) {
        this.strtForm = strtForm;
    }



    //        public static void main(String[] args) {
//        new MallForm("123456789").setVisible(true);//调用商城时请给出用户id，以对支付功能访问数据库
//
//    }
    public MallForm(String Uid) {
        userId = Uid;
        if(userId==null||userId.length()<=0)
            return;
        initComponents();
        pic1.setIcon(new ImageIcon(relativePath + "pic1.png"));//设置杀棋图片
        pic2.setIcon(new ImageIcon(relativePath + "pic2.png"));//设置变色棋图片
        pic3.setIcon(new ImageIcon(relativePath + "pic3.png"));//设置炸棋图片
        label34.setVisible(false);
        setVisible(false);

    }

    /*
     * 关闭商城
     * @e 鼠标点击事件*/
    private void buttonBackMouseClicked(MouseEvent e) {

        setVisible(false);//不显示商城
        strtForm.setVisible(true);

    }

    /*
     * 打开杀棋购买界面
     * @e 鼠标点击事件*/
    private void buttonPayItem1MouseClicked(MouseEvent e) {
        payPic1.setIcon(new ImageIcon(relativePath + "pic1.png"));//设置杀棋图片
        panelMall.setVisible(false);//不显示商城
        panelPayItem1.setVisible(true);//显示支付杀棋
        label31.setVisible(false);//隐藏购买状态
    }

    /*
     * 关闭杀棋购买界面
     * @e 鼠标点击事件*/
    private void buttonCancel1MouseClicked(MouseEvent e) {
        panelMall.setVisible(true);//显示商城
        panelPayItem1.setVisible(false);//不显示支付杀棋
        label34.setVisible(false);
    }

    /*
     * 关闭变色棋购买界面
     * @e 鼠标点击事件*/
    private void buttonCancel2MouseClicked(MouseEvent e) {
        panelMall.setVisible(true);//显示商城
        panelPayItem2.setVisible(false);//不显示支付变色棋
        label34.setVisible(false);
    }

    /*
     * 打开变色棋购买界面
     * @e 鼠标点击事件*/
    private void button4MouseClicked(MouseEvent e) {
        payPic2.setIcon(new ImageIcon(relativePath + "pic2.png"));//设置变色棋图片
        panelMall.setVisible(false);//不显示商城
        panelPayItem2.setVisible(true);//显示支付变色棋
        label32.setVisible(false);
    }

    /*
     * 打开炸棋购买界面
     * @e 鼠标点击事件*/
    private void button5MouseClicked(MouseEvent e) {
        payPic3.setIcon(new ImageIcon(relativePath + "pic3.png"));//设置炸棋图片
        panelMall.setVisible(false);//不显示商城
        panelPayItem3.setVisible(true);//显示支付炸棋
        label33.setVisible(false);
    }

    /*
     * 关闭杀棋购买界面
     * @e 鼠标点击事件*/
    private void buttonCancel3MouseClicked(MouseEvent e) {
        panelMall.setVisible(true);//显示商城
        panelPayItem3.setVisible(false);//不显示支付炸棋
        label34.setVisible(false);
    }

    /*
     * 杀棋数量减一
     * @e 鼠标点击事件*/
    private void buttonSub1MouseClicked(MouseEvent e) {
        int value = Integer.parseInt(textField1.getText()) - 1;//数量-1
        if (value < 0) {
            textField1.setText("0");//数量小于0置0
            label16.setText("总额:0积分");
        } else {
            textField1.setText(value + "");
            label16.setText("总额:" + value * 60 + "积分");
        }
        panelPayItem1.repaint();//刷新界面
    }

    /*
     * 变色棋数量减一
     * @e 鼠标点击事件*/
    private void buttonSub2MouseClicked(MouseEvent e) {
        int value = Integer.parseInt(textField2.getText()) - 1;//数量-1
        if (value < 0) {
            textField2.setText("0");//数量小于0置0
            label21.setText("总额:0积分");
        } else {
            textField2.setText(value + "");
            label21.setText("总额:" + value * 120 + "积分");
        }
        panelPayItem2.repaint();//刷新界面
    }

    /*
     * 炸棋数量减一
     * @e 鼠标点击事件*/
    private void buttonSub3MouseClicked(MouseEvent e) {
        int value = Integer.parseInt(textField3.getText()) - 1;//数量-1
        if (value < 0) {
            textField3.setText("0");//数量小于0置0
            label26.setText("总额:0积分");
        } else {
            textField3.setText(value + "");
            label26.setText("总额:" + value * 360 + "积分");
        }
        panelPayItem3.repaint();//刷新界面
    }

    /*
     * 杀棋数量加一
     * @e 鼠标点击事件*/
    private void buttonAdd1MouseClicked(MouseEvent e) {
        int value = Integer.parseInt(textField1.getText()) + 1;//数量+1
        textField1.setText(value + "");
        label16.setText("总额:" + value * 60 + "积分");
        panelPayItem1.repaint();//刷新界面
    }

    /*
     * 变色棋数量加一
     * @e 鼠标点击事件*/
    private void buttonAdd2MouseClicked(MouseEvent e) {
        int value = Integer.parseInt(textField2.getText()) + 1;//数量+1
        textField2.setText(value + "");
        label21.setText("总额:" + value * 120 + "积分");
        panelPayItem2.repaint();//刷新界面
    }

    /*
     * 炸棋数量加一
     * @e 鼠标点击事件*/
    private void buttonAdd3MouseClicked(MouseEvent e) {
        int value = Integer.parseInt(textField3.getText()) + 1;//数量+1
        textField3.setText(value + "");
        label26.setText("总额:" + value * 360 + "积分");
        panelPayItem3.repaint();//刷新界面
    }

    /*
     * 关闭积分充值
     * @e 鼠标点击事件*/
    private void buttonBack1MouseClicked(MouseEvent e) {
        panelScore.setVisible(false);//不显示积分充值
        panelMall.setVisible(true);//显示商城
    }

    /*
     * 显示积分充值
     * @e 鼠标点击事件*/
    private void buttonPayPointMouseClicked(MouseEvent e) {
        pointPic1.setIcon(new ImageIcon(relativePath + "pointPic1.png"));//设置积分充值333档图片
        pointPic2.setIcon(new ImageIcon(relativePath + "pointPic2.png"));//设置积分充值666档图片
        pointPic3.setIcon(new ImageIcon(relativePath + "pointPic3.png"));//设置积分充值999档图片
        panelMall.setVisible(false);//不显示商城
        panelScore.setVisible(true);//显示积分充值
    }

    /*
     * 购买道具杀棋
     * @e 鼠标点击事件*/
    private void pay1MouseClicked(MouseEvent e) {
        int score = 60 * Integer.parseInt(textField1.getText());
        if (score == 0) {
            label31.setText("数量为0");
            label31.setVisible(true);
            panelPayItem1.repaint();
            return;
        }
        Trade trade = new Trade();
        if (trade.purchasedItems(score, userId, "P01") == 1) {
            label31.setText("支付成功");
        } else {
            label31.setText("支付失败");
        }
        label31.setVisible(true);
        panelPayItem1.repaint();
    }

    /*
     * 购买道具变色棋
     * @e 鼠标点击事件*/
    private void pay2MouseClicked(MouseEvent e) {
        int score = 120 * Integer.parseInt(textField2.getText());
        if (score == 0) {
            label32.setText("数量为0");
            label32.setVisible(true);
            panelPayItem2.repaint();
            return;
        }
        Trade trade = new Trade();
        if (trade.purchasedItems(score, userId, "P02") == 1) {
            label32.setText("支付成功");
        } else {
            label32.setText("支付失败");
        }
        label32.setVisible(true);
        panelPayItem2.repaint();
    }

    /*
     * 购买道具炸棋
     * @e 鼠标点击事件*/
    private void pay3MouseClicked(MouseEvent e) {
        int score = 360 * Integer.parseInt(textField3.getText());
        if (score == 0) {
            label33.setText("数量为0");
            label33.setVisible(true);
            panelPayItem3.repaint();
            return;
        }
        Trade trade = new Trade();
        if (trade.purchasedItems(score, userId, "P03") == 1) {
            label33.setText("支付成功");
        } else {
            label33.setText("支付失败");
        }
        label33.setVisible(true);
        panelPayItem3.repaint();
    }

    /*
     * 积分充值第一档支付二维码显示
     * @e 鼠标点击事件*/
    private void buttonPayPoint1MouseClicked(MouseEvent e) {
        Main main = new Main();
        String orderNo = main.test_trade_precreate("3.33");//生成二维码并获取订单号
        try {
            picQRCode.setIcon(new ImageIcon(ImageIO.read(new File(relativePath + "qr.png"))));//设置二维码图片
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        panelQRCode.repaint();//刷新二维码界面
        panelQRCode.setVisible(true);//显示二维码
        panelScore.setVisible(false);//不显示积分充值
        thread = new Thread(new IsPaySuccess(main, orderNo, 333, userId, panelMall, panelQRCode, label34));
        thread.start();
    }

    /*
     * 积分充值第二档支付二维码显示
     * @e 鼠标点击事件*/
    private void buttonPayPoint2MouseClicked(MouseEvent e) {
        Main main = new Main();
        String orderNo = main.test_trade_precreate("6.66");//生成二维码并获取订单号
        try {
            picQRCode.setIcon(new ImageIcon(ImageIO.read(new File(relativePath + "qr.png"))));//设置二维码图片
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        panelQRCode.repaint();//刷新二维码界面
        panelQRCode.setVisible(true);//显示二维码
        panelScore.setVisible(false);//不显示积分充值
        thread = new Thread(new IsPaySuccess(main, orderNo, 666, userId, panelMall, panelQRCode, label34));
        thread.start();
    }

    /*
     * 积分充值第三档支付二维码显示
     * @e 鼠标点击事件*/
    private void buttonPayPoint3MouseClicked(MouseEvent e) {
        Main main = new Main();
        String orderNo = main.test_trade_precreate("9.99");//生成二维码并获取订单号
        try {
            picQRCode.setIcon(new ImageIcon(ImageIO.read(new File(relativePath + "qr.png"))));//设置二维码图片
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        panelQRCode.repaint();//刷新二维码界面
        panelQRCode.setVisible(true);//显示二维码
        panelScore.setVisible(false);//不显示积分充值
        thread = new Thread(new IsPaySuccess(main, orderNo, 999, userId, panelMall, panelQRCode, label34));
        thread.start();//线程启动
    }

    /*
     * 取消支付
     * @e 鼠标点击事件*/
    private void button1MouseClicked(MouseEvent e) {
        panelQRCode.setVisible(false);//不显示二维码
        panelMall.setVisible(true);//显示商城
        thread.stop();//停止监控支付线程
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        panelMall = new JPanel();
        label1 = new JLabel();
        buttonBack = new JButton();
        buttonPayPoint = new JButton();
        pic1 = new JLabel();
        pic2 = new JLabel();
        pic3 = new JLabel();
        label2 = new JLabel();
        label6 = new JLabel();
        label12 = new JLabel();
        label3 = new JLabel();
        label5 = new JLabel();
        label8 = new JLabel();
        label4 = new JLabel();
        label7 = new JLabel();
        label9 = new JLabel();
        label10 = new JLabel();
        label11 = new JLabel();
        buttonPayItem1 = new JButton();
        button4 = new JButton();
        button5 = new JButton();
        label34 = new JLabel();
        panelPayItem1 = new JPanel();
        payPic1 = new JLabel();
        label13 = new JLabel();
        label14 = new JLabel();
        label15 = new JLabel();
        textField1 = new JTextField();
        buttonSub1 = new JButton();
        buttonAdd1 = new JButton();
        label16 = new JLabel();
        pay1 = new JButton();
        label31 = new JLabel();
        label17 = new JLabel();
        buttonCancel1 = new JButton();
        panelPayItem2 = new JPanel();
        payPic2 = new JLabel();
        label18 = new JLabel();
        label19 = new JLabel();
        label20 = new JLabel();
        textField2 = new JTextField();
        buttonSub2 = new JButton();
        buttonAdd2 = new JButton();
        label21 = new JLabel();
        pay2 = new JButton();
        label22 = new JLabel();
        buttonCancel2 = new JButton();
        label32 = new JLabel();
        panelPayItem3 = new JPanel();
        payPic3 = new JLabel();
        label23 = new JLabel();
        label24 = new JLabel();
        label25 = new JLabel();
        textField3 = new JTextField();
        buttonSub3 = new JButton();
        buttonAdd3 = new JButton();
        label26 = new JLabel();
        pay3 = new JButton();
        label27 = new JLabel();
        buttonCancel3 = new JButton();
        label28 = new JLabel();
        label29 = new JLabel();
        label33 = new JLabel();
        panelScore = new JPanel();
        label30 = new JLabel();
        pointPic1 = new JLabel();
        pointPic3 = new JLabel();
        pointPic2 = new JLabel();
        buttonPayPoint1 = new JButton();
        buttonPayPoint2 = new JButton();
        buttonPayPoint3 = new JButton();
        buttonBack1 = new JButton();
        panelQRCode = new JPanel();
        picQRCode = new JLabel();
        button1 = new JButton();

        //======== this ========
        setVisible(true);
        setBackground(new Color(222, 222, 222));
        Container contentPane = getContentPane();
        contentPane.setLayout(null);

        //======== panelMall ========
        {
            panelMall.setLayout(null);

            //---- label1 ----
            label1.setText("\u5546\u57ce");
            label1.setFont(label1.getFont().deriveFont(label1.getFont().getSize() + 20f));
            panelMall.add(label1);
            label1.setBounds(new Rectangle(new Point(265, 25), label1.getPreferredSize()));

            //---- buttonBack ----
            buttonBack.setText("\u8fd4\u56de");
            buttonBack.setFont(buttonBack.getFont().deriveFont(buttonBack.getFont().getSize() + 8f));
            buttonBack.setBackground(new Color(222, 222, 222));
            buttonBack.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    buttonBackMouseClicked(e);
                }
            });
            panelMall.add(buttonBack);
            buttonBack.setBounds(580, 10, 114, buttonBack.getPreferredSize().height);

            //---- buttonPayPoint ----
            buttonPayPoint.setText("\u79ef\u5206\u5145\u503c");
            buttonPayPoint.setFont(buttonPayPoint.getFont().deriveFont(buttonPayPoint.getFont().getSize() + 8f));
            buttonPayPoint.setBackground(new Color(222, 222, 222));
            buttonPayPoint.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    buttonPayPointMouseClicked(e);
                }
            });
            panelMall.add(buttonPayPoint);
            buttonPayPoint.setBounds(new Rectangle(new Point(580, 55), buttonPayPoint.getPreferredSize()));

            //---- pic1 ----
            pic1.setIcon(null);
            panelMall.add(pic1);
            pic1.setBounds(30, 70, 150, 150);

            //---- pic2 ----
            pic2.setIcon(null);
            panelMall.add(pic2);
            pic2.setBounds(230, 70, 150, 150);

            //---- pic3 ----
            pic3.setIcon(null);
            panelMall.add(pic3);
            pic3.setBounds(420, 70, 150, 150);

            //---- label2 ----
            label2.setText("\u6740\u68cb");
            label2.setFont(label2.getFont().deriveFont(label2.getFont().getSize() + 6f));
            label2.setHorizontalTextPosition(SwingConstants.CENTER);
            panelMall.add(label2);
            label2.setBounds(85, 235, 50, label2.getPreferredSize().height);

            //---- label6 ----
            label6.setText("\u53d8\u8272\u68cb");
            label6.setFont(label6.getFont().deriveFont(label6.getFont().getSize() + 6f));
            panelMall.add(label6);
            label6.setBounds(280, 235, 65, label6.getPreferredSize().height);

            //---- label12 ----
            label12.setText("\u70b8\u68cb");
            label12.setFont(label12.getFont().deriveFont(label12.getFont().getSize() + 6f));
            panelMall.add(label12);
            label12.setBounds(475, 235, 50, label12.getPreferredSize().height);

            //---- label3 ----
            label3.setText("\u4ece\u68cb\u76d8\u4e0a\u53bb\u6389");
            label3.setFont(label3.getFont().deriveFont(label3.getFont().getSize() + 5f));
            panelMall.add(label3);
            label3.setBounds(new Rectangle(new Point(55, 285), label3.getPreferredSize()));

            //---- label5 ----
            label5.setText("\u6539\u53d8\u68cb\u76d8\u4e0a\u4efb\u610f");
            label5.setFont(label5.getFont().deriveFont(label5.getFont().getSize() + 5f));
            panelMall.add(label5);
            label5.setBounds(250, 280, 130, label5.getPreferredSize().height);

            //---- label8 ----
            label8.setText(" \u9009\u62e9\u4e00\u4e2a\u81ea\u5df1\u7684\u68cb\u5b50");
            label8.setFont(label8.getFont().deriveFont(label8.getFont().getSize() + 3f));
            panelMall.add(label8);
            label8.setBounds(425, 275, 146, label8.getPreferredSize().height);

            //---- label4 ----
            label4.setText("\u4efb\u610f\u4e00\u4e2a\u68cb\u5b50");
            label4.setFont(label4.getFont().deriveFont(label4.getFont().getSize() + 5f));
            panelMall.add(label4);
            label4.setBounds(new Rectangle(new Point(55, 325), label4.getPreferredSize()));

            //---- label7 ----
            label7.setText("\u4e00\u4e2a\u68cb\u5b50\u7684\u989c\u8272");
            label7.setFont(label7.getFont().deriveFont(label7.getFont().getSize() + 5f));
            panelMall.add(label7);
            label7.setBounds(250, 320, 127, label7.getPreferredSize().height);

            //---- label9 ----
            label9.setText("\u8ba9\u68cb\u5b50\u5468\u56f43x3\u7684\u68cb\u5b50");
            label9.setFont(label9.getFont().deriveFont(label9.getFont().getSize() + 3f));
            panelMall.add(label9);
            label9.setBounds(new Rectangle(new Point(425, 295), label9.getPreferredSize()));

            //---- label10 ----
            label10.setText("\u4ece\u68cb\u76d8\u4e0a\u53bb\u6389");
            label10.setFont(label10.getFont().deriveFont(label10.getFont().getSize() + 3f));
            panelMall.add(label10);
            label10.setBounds(450, 315, 110, label10.getPreferredSize().height);

            //---- label11 ----
            label11.setText("\u5305\u62ec\u81ea\u5df1\u7684\u68cb\u5b50");
            label11.setFont(label11.getFont().deriveFont(label11.getFont().getSize() + 3f));
            panelMall.add(label11);
            label11.setBounds(445, 340, 120, label11.getPreferredSize().height);

            //---- buttonPayItem1 ----
            buttonPayItem1.setText("\u8d2d\u4e70");
            buttonPayItem1.setFont(buttonPayItem1.getFont().deriveFont(buttonPayItem1.getFont().getSize() + 6f));
            buttonPayItem1.setBackground(new Color(222, 222, 222));
            buttonPayItem1.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    buttonPayItem1MouseClicked(e);
                }
            });
            panelMall.add(buttonPayItem1);
            buttonPayItem1.setBounds(65, 365, 80, buttonPayItem1.getPreferredSize().height);

            //---- button4 ----
            button4.setText("\u8d2d\u4e70");
            button4.setFont(button4.getFont().deriveFont(button4.getFont().getSize() + 6f));
            button4.setBackground(new Color(222, 222, 222));
            button4.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    button4MouseClicked(e);
                }
            });
            panelMall.add(button4);
            button4.setBounds(265, 365, 80, button4.getPreferredSize().height);

            //---- button5 ----
            button5.setText("\u8d2d\u4e70");
            button5.setFont(button5.getFont().deriveFont(button5.getFont().getSize() + 6f));
            button5.setBackground(new Color(222, 222, 222));
            button5.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    button5MouseClicked(e);
                }
            });
            panelMall.add(button5);
            button5.setBounds(455, 365, 80, button5.getPreferredSize().height);

            //---- label34 ----
            label34.setFont(label34.getFont().deriveFont(label34.getFont().getSize() + 8f));
            label34.setText("\u79ef\u5206\u5145\u503c\u6210\u529f!");
            panelMall.add(label34);
            label34.setBounds(250, 400, 300, label34.getPreferredSize().height);

            {
                // compute preferred size
                Dimension preferredSize = new Dimension();
                for(int i = 0; i < panelMall.getComponentCount(); i++) {
                    Rectangle bounds = panelMall.getComponent(i).getBounds();
                    preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                    preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                }
                Insets insets = panelMall.getInsets();
                preferredSize.width += insets.right;
                preferredSize.height += insets.bottom;
                panelMall.setMinimumSize(preferredSize);
                panelMall.setPreferredSize(preferredSize);
            }
        }
        contentPane.add(panelMall);
        panelMall.setBounds(35, 30, 700, 525);

        //======== panelPayItem1 ========
        {
            panelPayItem1.setVisible(false);
            panelPayItem1.setLayout(null);
            panelPayItem1.add(payPic1);
            payPic1.setBounds(210, 15, 150, 150);

            //---- label13 ----
            label13.setText("\u4ece\u68cb\u76d8\u4e0a\u53bb\u6389");
            label13.setFont(label13.getFont().deriveFont(label13.getFont().getSize() + 7f));
            panelPayItem1.add(label13);
            label13.setBounds(new Rectangle(new Point(230, 220), label13.getPreferredSize()));

            //---- label14 ----
            label14.setText("\u4efb\u610f\u4e00\u4e2a\u68cb\u5b50");
            label14.setFont(label14.getFont().deriveFont(label14.getFont().getSize() + 7f));
            panelPayItem1.add(label14);
            label14.setBounds(new Rectangle(new Point(230, 250), label14.getPreferredSize()));

            //---- label15 ----
            label15.setText("\u6570\u91cf:");
            label15.setFont(label15.getFont().deriveFont(label15.getFont().getSize() + 10f));
            panelPayItem1.add(label15);
            label15.setBounds(225, 300, 55, label15.getPreferredSize().height);

            //---- textField1 ----
            textField1.setText("1");
            textField1.setFont(textField1.getFont().deriveFont(textField1.getFont().getSize() + 12f));
            panelPayItem1.add(textField1);
            textField1.setBounds(285, 290, 50, textField1.getPreferredSize().height);

            //---- buttonSub1 ----
            buttonSub1.setText("<");
            buttonSub1.setFont(buttonSub1.getFont().deriveFont(buttonSub1.getFont().getSize() + 5f));
            buttonSub1.setBackground(new Color(222, 222, 222));
            buttonSub1.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    buttonSub1MouseClicked(e);
                }
            });
            panelPayItem1.add(buttonSub1);
            buttonSub1.setBounds(335, 285, 50, 50);

            //---- buttonAdd1 ----
            buttonAdd1.setText(">");
            buttonAdd1.setFont(buttonAdd1.getFont().deriveFont(buttonAdd1.getFont().getSize() + 5f));
            buttonAdd1.setBackground(new Color(222, 222, 222));
            buttonAdd1.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    buttonAdd1MouseClicked(e);
                }
            });
            panelPayItem1.add(buttonAdd1);
            buttonAdd1.setBounds(385, 285, 50, 50);

            //---- label16 ----
            label16.setText("\u603b\u989d:60\u79ef\u5206");
            label16.setFont(label16.getFont().deriveFont(label16.getFont().getSize() + 8f));
            panelPayItem1.add(label16);
            label16.setBounds(235, 345, 200, label16.getPreferredSize().height);

            //---- pay1 ----
            pay1.setText("\u652f\u4ed8");
            pay1.setFont(pay1.getFont().deriveFont(pay1.getFont().getSize() + 8f));
            pay1.setBackground(new Color(222, 222, 222));
            pay1.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    pay1MouseClicked(e);
                }
            });
            panelPayItem1.add(pay1);
            pay1.setBounds(new Rectangle(new Point(250, 380), pay1.getPreferredSize()));

            //---- label31 ----
            label31.setText("text");
            label31.setFont(label31.getFont().deriveFont(label31.getFont().getSize() + 8f));
            label31.setVisible(false);
            panelPayItem1.add(label31);
            label31.setBounds(340, 380, 100, label31.getPreferredSize().height);

            //---- label17 ----
            label17.setText("\u6740\u68cb");
            label17.setFont(label17.getFont().deriveFont(label17.getFont().getSize() + 8f));
            panelPayItem1.add(label17);
            label17.setBounds(new Rectangle(new Point(260, 185), label17.getPreferredSize()));

            //---- buttonCancel1 ----
            buttonCancel1.setText("\u53d6\u6d88");
            buttonCancel1.setFont(buttonCancel1.getFont().deriveFont(buttonCancel1.getFont().getSize() + 8f));
            buttonCancel1.setBackground(new Color(222, 222, 222));
            buttonCancel1.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    buttonCancel1MouseClicked(e);
                }
            });
            panelPayItem1.add(buttonCancel1);
            buttonCancel1.setBounds(new Rectangle(new Point(250, 420), buttonCancel1.getPreferredSize()));

            {
                // compute preferred size
                Dimension preferredSize = new Dimension();
                for(int i = 0; i < panelPayItem1.getComponentCount(); i++) {
                    Rectangle bounds = panelPayItem1.getComponent(i).getBounds();
                    preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                    preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                }
                Insets insets = panelPayItem1.getInsets();
                preferredSize.width += insets.right;
                preferredSize.height += insets.bottom;
                panelPayItem1.setMinimumSize(preferredSize);
                panelPayItem1.setPreferredSize(preferredSize);
            }
        }
        contentPane.add(panelPayItem1);
        panelPayItem1.setBounds(45, 15, 565, 480);

        //======== panelPayItem2 ========
        {
            panelPayItem2.setVisible(false);
            panelPayItem2.setLayout(null);
            panelPayItem2.add(payPic2);
            payPic2.setBounds(205, 15, 150, 150);

            //---- label18 ----
            label18.setText("\u6539\u53d8\u68cb\u76d8\u4e0a\u4efb\u610f");
            label18.setFont(label18.getFont().deriveFont(label18.getFont().getSize() + 7f));
            panelPayItem2.add(label18);
            label18.setBounds(new Rectangle(new Point(215, 195), label18.getPreferredSize()));

            //---- label19 ----
            label19.setText("\u4e00\u4e2a\u68cb\u5b50\u7684\u989c\u8272");
            label19.setFont(label19.getFont().deriveFont(label19.getFont().getSize() + 7f));
            panelPayItem2.add(label19);
            label19.setBounds(new Rectangle(new Point(215, 230), label19.getPreferredSize()));

            //---- label20 ----
            label20.setText("\u6570\u91cf:");
            label20.setFont(label20.getFont().deriveFont(label20.getFont().getSize() + 10f));
            panelPayItem2.add(label20);
            label20.setBounds(190, 275, 55, label20.getPreferredSize().height);

            //---- textField2 ----
            textField2.setText("1");
            textField2.setFont(textField2.getFont().deriveFont(textField2.getFont().getSize() + 12f));
            panelPayItem2.add(textField2);
            textField2.setBounds(255, 270, 50, textField2.getPreferredSize().height);

            //---- buttonSub2 ----
            buttonSub2.setText("<");
            buttonSub2.setFont(buttonSub2.getFont().deriveFont(buttonSub2.getFont().getSize() + 5f));
            buttonSub2.setBackground(new Color(222, 222, 222));
            buttonSub2.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    buttonSub2MouseClicked(e);
                }
            });
            panelPayItem2.add(buttonSub2);
            buttonSub2.setBounds(305, 265, 50, 50);

            //---- buttonAdd2 ----
            buttonAdd2.setText(">");
            buttonAdd2.setFont(buttonAdd2.getFont().deriveFont(buttonAdd2.getFont().getSize() + 5f));
            buttonAdd2.setBackground(new Color(222, 222, 222));
            buttonAdd2.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    buttonAdd2MouseClicked(e);
                }
            });
            panelPayItem2.add(buttonAdd2);
            buttonAdd2.setBounds(355, 265, 50, 50);

            //---- label21 ----
            label21.setText("\u603b\u989d:120\u79ef\u5206");
            label21.setFont(label21.getFont().deriveFont(label21.getFont().getSize() + 8f));
            panelPayItem2.add(label21);
            label21.setBounds(220, 325, 200, label21.getPreferredSize().height);

            //---- pay2 ----
            pay2.setText("\u652f\u4ed8");
            pay2.setFont(pay2.getFont().deriveFont(pay2.getFont().getSize() + 8f));
            pay2.setBackground(new Color(222, 222, 222));
            pay2.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    pay2MouseClicked(e);
                }
            });
            panelPayItem2.add(pay2);
            pay2.setBounds(new Rectangle(new Point(240, 360), pay2.getPreferredSize()));

            //---- label22 ----
            label22.setText("\u53d8\u8272\u68cb");
            label22.setFont(label22.getFont().deriveFont(label22.getFont().getSize() + 8f));
            panelPayItem2.add(label22);
            label22.setBounds(new Rectangle(new Point(250, 165), label22.getPreferredSize()));

            //---- buttonCancel2 ----
            buttonCancel2.setText("\u53d6\u6d88");
            buttonCancel2.setFont(buttonCancel2.getFont().deriveFont(buttonCancel2.getFont().getSize() + 8f));
            buttonCancel2.setBackground(new Color(222, 222, 222));
            buttonCancel2.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    buttonCancel1MouseClicked(e);
                    buttonCancel2MouseClicked(e);
                }
            });
            panelPayItem2.add(buttonCancel2);
            buttonCancel2.setBounds(new Rectangle(new Point(240, 400), buttonCancel2.getPreferredSize()));

            //---- label32 ----
            label32.setText("text");
            label32.setFont(label32.getFont().deriveFont(label32.getFont().getSize() + 8f));
            label32.setVisible(false);
            panelPayItem2.add(label32);
            label32.setBounds(320, 360, 100, 27);

            {
                // compute preferred size
                Dimension preferredSize = new Dimension();
                for(int i = 0; i < panelPayItem2.getComponentCount(); i++) {
                    Rectangle bounds = panelPayItem2.getComponent(i).getBounds();
                    preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                    preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                }
                Insets insets = panelPayItem2.getInsets();
                preferredSize.width += insets.right;
                preferredSize.height += insets.bottom;
                panelPayItem2.setMinimumSize(preferredSize);
                panelPayItem2.setPreferredSize(preferredSize);
            }
        }
        contentPane.add(panelPayItem2);
        panelPayItem2.setBounds(45, 15, 565, 450);

        //======== panelPayItem3 ========
        {
            panelPayItem3.setVisible(false);
            panelPayItem3.setLayout(null);
            panelPayItem3.add(payPic3);
            payPic3.setBounds(215, 12, 150, 150);

            //---- label23 ----
            label23.setText("\u9009\u62e9\u4e00\u4e2a\u81ea\u5df1\u7684\u68cb\u5b50");
            label23.setFont(label23.getFont().deriveFont(label23.getFont().getSize() + 4f));
            panelPayItem3.add(label23);
            label23.setBounds(new Rectangle(new Point(225, 195), label23.getPreferredSize()));

            //---- label24 ----
            label24.setFont(label24.getFont().deriveFont(label24.getFont().getSize() + 4f));
            label24.setText("\u8ba9\u68cb\u5b50\u5468\u56f43x3\u7684\u68cb\u5b50");
            panelPayItem3.add(label24);
            label24.setBounds(new Rectangle(new Point(220, 215), label24.getPreferredSize()));

            //---- label25 ----
            label25.setText("\u6570\u91cf:");
            label25.setFont(label25.getFont().deriveFont(label25.getFont().getSize() + 10f));
            panelPayItem3.add(label25);
            label25.setBounds(195, 290, 55, label25.getPreferredSize().height);

            //---- textField3 ----
            textField3.setText("1");
            textField3.setFont(textField3.getFont().deriveFont(textField3.getFont().getSize() + 12f));
            panelPayItem3.add(textField3);
            textField3.setBounds(260, 290, 50, textField3.getPreferredSize().height);

            //---- buttonSub3 ----
            buttonSub3.setText("<");
            buttonSub3.setFont(buttonSub3.getFont().deriveFont(buttonSub3.getFont().getSize() + 5f));
            buttonSub3.setBackground(new Color(222, 222, 222));
            buttonSub3.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    buttonSub3MouseClicked(e);
                }
            });
            panelPayItem3.add(buttonSub3);
            buttonSub3.setBounds(315, 285, 50, 50);

            //---- buttonAdd3 ----
            buttonAdd3.setText(">");
            buttonAdd3.setFont(buttonAdd3.getFont().deriveFont(buttonAdd3.getFont().getSize() + 5f));
            buttonAdd3.setBackground(new Color(222, 222, 222));
            buttonAdd3.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    buttonAdd3MouseClicked(e);
                }
            });
            panelPayItem3.add(buttonAdd3);
            buttonAdd3.setBounds(365, 285, 50, 50);

            //---- label26 ----
            label26.setText("\u603b\u989d:360\u79ef\u5206");
            label26.setFont(label26.getFont().deriveFont(label26.getFont().getSize() + 8f));
            panelPayItem3.add(label26);
            label26.setBounds(230, 345, 200, label26.getPreferredSize().height);

            //---- pay3 ----
            pay3.setText("\u652f\u4ed8");
            pay3.setFont(pay3.getFont().deriveFont(pay3.getFont().getSize() + 8f));
            pay3.setBackground(new Color(222, 222, 222));
            pay3.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    pay3MouseClicked(e);
                }
            });
            panelPayItem3.add(pay3);
            pay3.setBounds(new Rectangle(new Point(245, 380), pay3.getPreferredSize()));

            //---- label27 ----
            label27.setText("\u70b8\u68cb");
            label27.setFont(label27.getFont().deriveFont(label27.getFont().getSize() + 8f));
            panelPayItem3.add(label27);
            label27.setBounds(new Rectangle(new Point(270, 165), label27.getPreferredSize()));

            //---- buttonCancel3 ----
            buttonCancel3.setText("\u53d6\u6d88");
            buttonCancel3.setFont(buttonCancel3.getFont().deriveFont(buttonCancel3.getFont().getSize() + 8f));
            buttonCancel3.setBackground(new Color(222, 222, 222));
            buttonCancel3.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    buttonCancel1MouseClicked(e);
                    buttonCancel2MouseClicked(e);
                    buttonCancel3MouseClicked(e);
                }
            });
            panelPayItem3.add(buttonCancel3);
            buttonCancel3.setBounds(new Rectangle(new Point(245, 420), buttonCancel3.getPreferredSize()));

            //---- label28 ----
            label28.setText("\u4ece\u68cb\u76d8\u4e0a\u53bb\u6389");
            label28.setFont(label28.getFont().deriveFont(label28.getFont().getSize() + 4f));
            panelPayItem3.add(label28);
            label28.setBounds(new Rectangle(new Point(245, 240), label28.getPreferredSize()));

            //---- label29 ----
            label29.setText("\u5305\u62ec\u81ea\u5df1\u7684\u68cb\u5b50");
            label29.setFont(label29.getFont().deriveFont(label29.getFont().getSize() + 4f));
            panelPayItem3.add(label29);
            label29.setBounds(new Rectangle(new Point(240, 265), label29.getPreferredSize()));

            //---- label33 ----
            label33.setText("text");
            label33.setFont(label33.getFont().deriveFont(label33.getFont().getSize() + 8f));
            label33.setVisible(false);
            panelPayItem3.add(label33);
            label33.setBounds(335, 380, 100, 27);

            {
                // compute preferred size
                Dimension preferredSize = new Dimension();
                for(int i = 0; i < panelPayItem3.getComponentCount(); i++) {
                    Rectangle bounds = panelPayItem3.getComponent(i).getBounds();
                    preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                    preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                }
                Insets insets = panelPayItem3.getInsets();
                preferredSize.width += insets.right;
                preferredSize.height += insets.bottom;
                panelPayItem3.setMinimumSize(preferredSize);
                panelPayItem3.setPreferredSize(preferredSize);
            }
        }
        contentPane.add(panelPayItem3);
        panelPayItem3.setBounds(45, 15, 565, 489);

        //======== panelScore ========
        {
            panelScore.setVisible(false);
            panelScore.setLayout(null);

            //---- label30 ----
            label30.setText("\u79ef\u5206\u52a9\u529b\u5305");
            label30.setFont(label30.getFont().deriveFont(label30.getFont().getSize() + 30f));
            panelScore.add(label30);
            label30.setBounds(new Rectangle(new Point(160, 30), label30.getPreferredSize()));
            panelScore.add(pointPic1);
            pointPic1.setBounds(15, 105, 158, 137);
            panelScore.add(pointPic3);
            pointPic3.setBounds(360, 105, 154, 133);
            panelScore.add(pointPic2);
            pointPic2.setBounds(190, 105, 155, 133);

            //---- buttonPayPoint1 ----
            buttonPayPoint1.setText("\u8d2d\u4e70");
            buttonPayPoint1.setFont(buttonPayPoint1.getFont().deriveFont(buttonPayPoint1.getFont().getSize() + 8f));
            buttonPayPoint1.setBackground(new Color(222, 222, 222));
            buttonPayPoint1.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    buttonPayPoint1MouseClicked(e);
                }
            });
            panelScore.add(buttonPayPoint1);
            buttonPayPoint1.setBounds(new Rectangle(new Point(50, 260), buttonPayPoint1.getPreferredSize()));

            //---- buttonPayPoint2 ----
            buttonPayPoint2.setText("\u8d2d\u4e70");
            buttonPayPoint2.setFont(buttonPayPoint2.getFont().deriveFont(buttonPayPoint2.getFont().getSize() + 8f));
            buttonPayPoint2.setBackground(new Color(222, 222, 222));
            buttonPayPoint2.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    buttonPayPoint2MouseClicked(e);
                }
            });
            panelScore.add(buttonPayPoint2);
            buttonPayPoint2.setBounds(230, 260, 78, 33);

            //---- buttonPayPoint3 ----
            buttonPayPoint3.setText("\u8d2d\u4e70");
            buttonPayPoint3.setFont(buttonPayPoint3.getFont().deriveFont(buttonPayPoint3.getFont().getSize() + 8f));
            buttonPayPoint3.setBackground(new Color(222, 222, 222));
            buttonPayPoint3.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    buttonPayPoint3MouseClicked(e);
                }
            });
            panelScore.add(buttonPayPoint3);
            buttonPayPoint3.setBounds(400, 260, 78, 33);

            //---- buttonBack1 ----
            buttonBack1.setText("\u8fd4\u56de");
            buttonBack1.setFont(buttonBack1.getFont().deriveFont(buttonBack1.getFont().getSize() + 8f));
            buttonBack1.setBackground(new Color(222, 222, 222));
            buttonBack1.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    buttonBack1MouseClicked(e);
                }
            });
            panelScore.add(buttonBack1);
            buttonBack1.setBounds(400, 20, 114, 33);

            {
                // compute preferred size
                Dimension preferredSize = new Dimension();
                for(int i = 0; i < panelScore.getComponentCount(); i++) {
                    Rectangle bounds = panelScore.getComponent(i).getBounds();
                    preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                    preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                }
                Insets insets = panelScore.getInsets();
                preferredSize.width += insets.right;
                preferredSize.height += insets.bottom;
                panelScore.setMinimumSize(preferredSize);
                panelScore.setPreferredSize(preferredSize);
            }
        }
        contentPane.add(panelScore);
        panelScore.setBounds(45, 15, 535, 320);

        //======== panelQRCode ========
        {
            panelQRCode.setVisible(false);
            panelQRCode.setLayout(null);
            panelQRCode.add(picQRCode);
            picQRCode.setBounds(50, 55, 300, 300);

            //---- button1 ----
            button1.setText("\u53d6\u6d88");
            button1.setFont(button1.getFont().deriveFont(button1.getFont().getSize() + 8f));
            button1.setBackground(new Color(222, 222, 222));
            button1.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    button1MouseClicked(e);
                }
            });
            panelQRCode.add(button1);
            button1.setBounds(new Rectangle(new Point(160, 360), button1.getPreferredSize()));

            {
                // compute preferred size
                Dimension preferredSize = new Dimension();
                for(int i = 0; i < panelQRCode.getComponentCount(); i++) {
                    Rectangle bounds = panelQRCode.getComponent(i).getBounds();
                    preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                    preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                }
                Insets insets = panelQRCode.getInsets();
                preferredSize.width += insets.right;
                preferredSize.height += insets.bottom;
                panelQRCode.setMinimumSize(preferredSize);
                panelQRCode.setPreferredSize(preferredSize);
            }
        }
        contentPane.add(panelQRCode);
        panelQRCode.setBounds(150, 80, 400, 400);

        {
            // compute preferred size
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < contentPane.getComponentCount(); i++) {
                Rectangle bounds = contentPane.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = contentPane.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            contentPane.setMinimumSize(preferredSize);
            contentPane.setPreferredSize(preferredSize);
        }
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents

        setVisible(false);

    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JPanel panelMall;
    private JLabel label1;
    private JButton buttonBack;
    private JButton buttonPayPoint;
    private JLabel pic1;
    private JLabel pic2;
    private JLabel pic3;
    private JLabel label2;
    private JLabel label6;
    private JLabel label12;
    private JLabel label3;
    private JLabel label5;
    private JLabel label8;
    private JLabel label4;
    private JLabel label7;
    private JLabel label9;
    private JLabel label10;
    private JLabel label11;
    private JButton buttonPayItem1;
    private JButton button4;
    private JButton button5;
    private JLabel label34;
    private JPanel panelPayItem1;
    private JLabel payPic1;
    private JLabel label13;
    private JLabel label14;
    private JLabel label15;
    private JTextField textField1;
    private JButton buttonSub1;
    private JButton buttonAdd1;
    private JLabel label16;
    private JButton pay1;
    private JLabel label31;
    private JLabel label17;
    private JButton buttonCancel1;
    private JPanel panelPayItem2;
    private JLabel payPic2;
    private JLabel label18;
    private JLabel label19;
    private JLabel label20;
    private JTextField textField2;
    private JButton buttonSub2;
    private JButton buttonAdd2;
    private JLabel label21;
    private JButton pay2;
    private JLabel label22;
    private JButton buttonCancel2;
    private JLabel label32;
    private JPanel panelPayItem3;
    private JLabel payPic3;
    private JLabel label23;
    private JLabel label24;
    private JLabel label25;
    private JTextField textField3;
    private JButton buttonSub3;
    private JButton buttonAdd3;
    private JLabel label26;
    private JButton pay3;
    private JLabel label27;
    private JButton buttonCancel3;
    private JLabel label28;
    private JLabel label29;
    private JLabel label33;
    private JPanel panelScore;
    private JLabel label30;
    private JLabel pointPic1;
    private JLabel pointPic3;
    private JLabel pointPic2;
    private JButton buttonPayPoint1;
    private JButton buttonPayPoint2;
    private JButton buttonPayPoint3;
    private JButton buttonBack1;
    private JPanel panelQRCode;
    private JLabel picQRCode;
    private JButton button1;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}

/*监控支付成功的进程类*/
class IsPaySuccess implements Runnable {
    Main main;
    String orderNo;
    int items;
    String userId;
    JPanel mall;
    JPanel qr;
    JLabel label;

    public IsPaySuccess(Main main, String orderNo, int score, String userId, JPanel mall, JPanel qr, JLabel label) {
        this.main = main;
        this.orderNo = orderNo;
        this.items = score;
        this.userId = userId;
        this.mall = mall;
        this.qr = qr;
        this.label = label;
    }

    @Override
    public void run() {
        while (true) {
            try {
                sleep(1500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            String result = main.test_trade_query(orderNo);//查询订单状态
            if (result.equals("SUCCESS")) {
                Trade trade = new Trade();

                trade.pointsRecharge(items, userId);//充积分
                mall.setVisible(true);//显示商城
                qr.setVisible(false);//关闭二维码
                label.setVisible(true);
                return;
            }
        }

    }
}
